
var EventEmitter = require('events').EventEmitter;
var _eventEmitter = new EventEmitter();
_eventEmitter.setMaxListeners(0);

window.EventManager = {

    properties: {
        // _eventEmitter: EventEmitter,
    },

    // ctor: function () {

    // },

    on: function (eventName, func) {
        _eventEmitter.on(eventName, func);
    },

    once: function (eventName, func) {
        _eventEmitter.once(eventName, func);
    },

    emit: function (eventName, self, param) {
        if (self && param) {
            _eventEmitter.emit(eventName, self, param);
            return;
        }
        if (self) {
            _eventEmitter.emit(eventName, self);
            return;
        }

        if (param) {
            _eventEmitter.emit(eventName, param);
            return;
        }
        _eventEmitter.emit(eventName);
    },

    removeListener: function (eventName, func) {
        if (func) {
            return _eventEmitter.removeListener(eventName, func);
        }
        _eventEmitter.removeAllListeners(eventName);
    },
};
